<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*, com.xpy.utils.ConnSqlServer" %>
<!DOCTYPE html>
<html>
<head>
    <title>登录结果</title>
    <style>
        body {
            text-align: center;
            padding-top: 100px;
            font-family: Arial, sans-serif;
        }
        .message {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .success {
            background-color: #dff0d8;
            color: #3c763d;
        }
        .error {
            background-color: #f2dede;
            color: #a94442;
        }
    </style>
</head>
<body>
<%
    // 获取表单提交的用户名和密码
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    // 尝试连接数据库并验证用户
    try (Connection conn = ConnSqlServer.getConnection()) {
        // 编写SQL查询语句，检查用户名和密码
        String sql = "SELECT COUNT(*) FROM users WHERE name = ? AND pwd = ?";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            pstmt.setString(1, username);
            pstmt.setString(2, password);

            try (ResultSet rs = pstmt.executeQuery()) {
                if (rs.next() && rs.getInt(1) > 0) {
                    // 登录成功
%>
<div class="message success">
    <p>欢迎登录，<%= username %>！</p>
    <!-- <jsp:forward page="admin_admin.jsp" /> -->
</div>
<%
} else {
    // 登录失败
%>
<div class="message error">
    <p>用户名或密码错误，请重新登录。</p>
</div>
<%
            }
        }
    }
} catch (SQLException e) {
    e.printStackTrace();
%>
<div class="message error">
    <p>登录时发生错误，请稍后再试。</p>
</div>
<%
    }
%>
<div class="message">
    <a href="ulogin.jsp">返回登录页面</a>
</div>
</body>
</html>